package com.general.app.xtgl.service.impl;


import java.util.ArrayList;
import java.util.List;

import com.general.app.xtgl.dao.ICompanyDao;
import com.general.app.xtgl.dao.entity.CompanyModel;
import com.general.app.xtgl.service.ICompanyService;
import com.general.common.exception.BusinessException;
import com.general.common.security.entity.User;
import com.general.common.service.impl.BaseServiceImpl;
import com.general.utils.base.StringUtil;

/**
 * 单位信息管理 
 * 
 * 
 * @author Administrator
 *
 */
public class CompanyServiceImpl extends BaseServiceImpl<CompanyModel, ICompanyDao> implements ICompanyService{

	/**
	 * 保存单位信息
	 */
	public boolean saveCompany(CompanyModel company) throws BusinessException {
		boolean returnFlg = false;
		int count = dao.saveCompany(company);
		if(count >0){
			returnFlg = true;
		}
		return returnFlg;
	}
	
	/**
	 * 批量删除单位信息
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	public String scDwxx(String ids, User user) throws Exception {
		
		if (!StringUtil.isEmpty(ids)) {
			String[] pks = ids.split(",");
			List<CompanyModel> list = new ArrayList<CompanyModel>();			
			for (int i = 0; i < pks.length; i++) {
				CompanyModel model = new CompanyModel();
				model.setCompany_id(pks[i]);
				//model.setUpdate_nm(user.getUserid());
				list.add(model);
			}
			
			int count = dao.batchDelete(list);			
			return count==pks.length ? "删除成功！" : "成功删除单位信息"+count+"条,"+(pks.length-count)+"条由于与其它业务关联不能删除！";
			
		}
		throw new Exception("删除列值为空！");
	}
	
	/**
	 * 根据单位名称取得单位
	 * @param company_name
	 * @return
	 */
	public CompanyModel getModelByName(String company_name){
		return dao.getModelByName(company_name);
	}
}
